Move OpenJDK installation from xaprepare to MSBuild NoTargets project#11348
Move OpenJDK installation from xaprepare to MSBuild NoTargets project#11348jonathanpeppers wants to merge 7 commits into
Conversation
Migrate the JDK download/install from the xaprepare bootstrapper (Step_InstallAdoptOpenJDK) to a new src/openjdk MSBuild NoTargets project, modeled after src/binutils. The new project: - Downloads the Microsoft OpenJDK archive (platform-specific) - Downloads and verifies hash of all downloads - Extracts and installs to $(AndroidToolchainDirectory)/jdk-21 - Supports incremental builds via MSBuild Inputs/Outputs - Validates root directory and key JDK files after install - Handles Windows (.zip via Unzip task) and Linux/macOS (.tar.gz via tar) - Handles macOS Contents/Home subdirectory structure Projects that depend on the JDK now have a ProjectReference to src/openjdk, ensuring correct build ordering: - src/manifestmerger (gradle + JAVA_HOME) - src/r8 (gradle + JAVA_HOME) - src/proguard-android (gradle + JAVA_HOME) - src/bundletool (uses jar to extract/repack) - src/java-runtime (uses javac, jar, java) Also removes all JI_JAVA_HOME usage, which was a redundant alias for JAVA_HOME set in CI pipelines. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ts project Create a new src/androidsdk MSBuild NoTargets project that runs sdkmanager --licenses with JAVA_HOME set correctly. This project depends on src/openjdk via ProjectReference, ensuring the JDK is installed before sdkmanager runs. The gradle/JDK-dependent projects now reference androidsdk instead of openjdk directly, since androidsdk transitively depends on openjdk. Remove the AcceptLicenses method from xaprepare Step_Android_SDK_NDK, which was failing in CI because it ran before the JDK was installed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0381336 to
e1571c5
Compare
Test projects that import TestApks.targets call sdkmanager with JAVA_HOME, so they need androidsdk to ensure the JDK is installed first. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rs.targets Test binding projects that import Jar.targets call javac/jar with JavaSdkDirectory, and Mono.Android imports JavaCallableWrappers.targets which runs D8 with JAVA_HOME. Both need the JDK installed first. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ProjectReference in .targets files does not work. Add it directly to Emulator.csproj which is the project built standalone by the CI pipeline to start/stop the Android emulator. This ensures the JDK is installed before sdkmanager is called. Revert the ineffective .targets changes from the previous commit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ProjectReference from Emulator.csproj to androidsdk is not sufficient because the project is built standalone by the pipeline and the reference is not resolved in time. Add an explicit build step in setup-test-environment-steps.yaml after xaprepare to ensure the JDK is installed and SDK licenses are accepted before any test project that needs Java runs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/review |
|
✅ Android PR Reviewer completed successfully! |
There was a problem hiding this comment.
Pull request overview
Migrates Microsoft OpenJDK installation from the xaprepare C# bootstrapper (Step_InstallAdoptOpenJDK*) into a new MSBuild NoTargets project (src/openjdk), modeled after src/binutils. A second new MSBuild project (src/androidsdk) takes over Android SDK license acceptance (previously AcceptLicenses in Step_Android_SDK_NDK). Projects that need a JDK at build time (manifestmerger, r8, proguard-android, bundletool, java-runtime, and the test Emulator.csproj) gain a ProjectReference to androidsdk/openjdk to enforce build ordering. The JI_JAVA_HOME alias is removed across CI, MSBuild, and test helpers, and dead OpenJDK constants are pruned from all Configurables.* partials.
Changes:
- Add
src/openjdk(download/verify/extract/install Microsoft OpenJDK) andsrc/androidsdk(accept SDK licenses), wired in viaXamarin.Android.slnandProjectReferences. - Delete
Step_InstallAdoptOpenJDK*.cs,Step_Android_SDK_NDK.AcceptLicenses, and unusedMicrosoftOpenJDK*/AdoptOpenJDK*/OpenJDKInstallDir/OpenJDKCacheDirdefinitions; remove the OpenJDK steps from the standard and test scenarios. - Drop all
JI_JAVA_HOME/JI_JAVA_HOME_DEFAULTusage fromsetup-jdk-variables.yaml,azure-pipelines-nightly.yaml,OS.InitOS, andAndroidSdkResolver; introduce a CI step that buildsandroidsdk.csprojto perform the JDK install + license acceptance.
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| Xamarin.Android.sln | Registers the new openjdk and androidsdk projects. |
| Configuration.props | Introduces MicrosoftOpenJDKVersion/Folder/RootDirName and unconditionally sets JavaSdkDirectory to the install location. |
| src/openjdk/openjdk.csproj, openjdk.targets | New NoTargets project that downloads, hash-verifies, extracts, and installs the Microsoft OpenJDK. |
| src/androidsdk/androidsdk.csproj, androidsdk.targets | New NoTargets project that runs sdkmanager --licenses to accept Android SDK licenses, taking a ProjectReference on openjdk. |
| src/manifestmerger/manifestmerger.csproj, src/r8/r8.csproj, src/proguard-android/proguard-android.csproj, src/bundletool/bundletool.csproj, src/java-runtime/java-runtime.csproj | Add ProjectReference to androidsdk so JDK is available before gradle/jar/javac steps. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Emulator.csproj | Adds ProjectReference to androidsdk for test environment. |
| src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/AndroidSdkResolver.cs | Removes JI_JAVA_HOME lookup. |
| build-tools/xaprepare/.../Step_InstallAdoptOpenJDK*.cs | Deletes all five OpenJDK install step files. |
| build-tools/xaprepare/.../Step_Android_SDK_NDK.cs | Removes AcceptLicenses and its callers (now handled by androidsdk.csproj). |
| build-tools/xaprepare/.../Scenario_Standard.cs, Scenario_AndroidTestDependencies.cs, Scenario_EmulatorTestDependencies.cs | Drops Step_InstallMicrosoftOpenJDK and updates descriptions. |
| build-tools/xaprepare/.../OperatingSystems/OS.cs | JavaHome no longer falls back to JI_JAVA_HOME. |
| build-tools/xaprepare/.../ConfigAndData/Configurables*.cs | Removes unused OpenJDK constants, URLs, paths, and cached fields. |
| build-tools/automation/yaml-templates/setup-test-environment-steps.yaml | Adds a step that builds androidsdk.csproj to install JDK and accept licenses. |
| build-tools/automation/yaml-templates/setup-jdk-variables.yaml | Stops setting JI_JAVA_HOME / JI_JAVA_HOME_DEFAULT. |
| build-tools/automation/azure-pipelines-nightly.yaml | Switches JavaSdkDirectory arg from $(JI_JAVA_HOME_DEFAULT) to $(JAVA_HOME). |
There was a problem hiding this comment.
✅ LGTM
Clean, well-structured migration that follows the established binutils pattern. The dependency graph (projects → androidsdk → openjdk) correctly ensures JDK is installed before any Java-dependent build step, and the removal of JI_JAVA_HOME simplifies CI without leaving dangling references.
Positive callouts:
- SHA-256 hash verification of downloads is a good security improvement over the old code (which only checked version strings)
- Incremental build support via
Inputs/Outputson all targets is correct - The separation of
openjdk(download/install JDK) fromandroidsdk(accept licenses) is a clean abstraction - CI yaml cleanup (removing
JI_JAVA_HOME,JI_JAVA_HOME_DEFAULT) is thorough
Issues: 0 ❌ | 0
Generated by Android PR Reviewer for issue #11348 · ● 12.6M
98a580f to
59f1c2a
Compare
Fix 1: PowerShell "y" * 10 produces one string "yyyyyyyyyy", not 10
separate lines. Use 1..10 | ForEach-Object { "y" } instead.
Fix 2: Simplify JDK installation to a single tar call that extracts
directly into the install directory using --strip-components to flatten
the archive root folder. Windows 10+ includes bsdtar which handles
both .zip and .tar.gz. On macOS, strip 3 levels (jdk-X/Contents/Home)
vs 1 level (jdk-X) on Windows/Linux.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
59f1c2a to
3eaa5df
Compare
Migrates the JDK download/install from the xaprepare bootstrapper (
Step_InstallAdoptOpenJDK) to a newsrc/openjdkMSBuild NoTargets project, modeled aftersrc/binutils.New
src/openjdkproject$(AndroidToolchainDirectory)/jdk-21Inputs/Outputs.zipviaUnziptask) and Linux/macOS (.tar.gzviatar)Contents/Homesubdirectory structureProjectReferences
Projects that depend on the JDK now have a
ProjectReferencetosrc/openjdk, ensuring correct build ordering:src/manifestmerger(gradle + JAVA_HOME)src/r8(gradle + JAVA_HOME)src/proguard-android(gradle + JAVA_HOME)src/bundletool(uses jar to extract/repack)src/java-runtime(uses javac, jar, java)Cleanup
Step_InstallAdoptOpenJDK*.csfilesConfigurablespartial filesJI_JAVA_HOMEusage (redundant alias forJAVA_HOMEset in CI)